package compiler;
%%

%public
// %standalone
%class Scanner
%caseless
%line
%column
// %byaccj

%{
	public static void show(String token, String value, int line, int column){
		System.out.println((line+1)+","+(column+1)+": ("+token+", "+value+")");
	}
%}

// Macro definitions
LineTerminator = \r|\n|\r\n
InputCharacter = [^\r\n]
EndOfLineComment     = "//" {InputCharacter}* {LineTerminator}
blank = 	[ \t\n\r]
digit = 	[0-9]
letter=		[A-Za-z]
ident = 	{letter}({letter}|{digit})*
int =		{digit}+
begin =		(BEGIN)
end = 		(END)
of = 		(OF)
then=	 	(THEN) 
do=		(DO)
print=		(PRINT) 
read=		(READ)
else=		(ELSE) 
elsif=		(ELSIF) 
if=		(IF) 
while=		(WHILE) 
repeat=		(REPEAT) 
until=		(UNTIL)
array=		(ARRAY)
record= 	(RECORD) 
const=		(CONST) 
type=		(TYPE)
var=		(VAR)
procedure=	(PROCEDURE)  
module=		(MODULE)
operator=	[*+-/=#()\"<>.,:;] | (:=) | (>=) | (<=) | ("[") | ("]")
string=		\"[^\"]*\"
literal=	{of}|{then}|{do}|{print}|{read}|{else}|{elsif}|{if}|{while}|{repeat}|{until}|{array}|{record}|{const}|{type}|{var}|{procedure}|{module}



%%
// Lexical rules

{blank}				{}
{EndOfLineComment}	{}
{begin}				{show("Begin",yytext(),yyline,yycolumn); return new Yytoken("Begin",yytext(),yyline+1,yycolumn+1);}
{end}				{show("End",yytext(),yyline,yycolumn); return new Yytoken("End",yytext(),yyline+1,yycolumn+1);}
{literal}			{show("Literal",yytext(),yyline,yycolumn); return new Yytoken("Literal",yytext(),yyline+1,yycolumn+1);}
{ident}				{show("Ident",yytext(),yyline,yycolumn); return new Yytoken("Ident",yytext(),yyline+1,yycolumn+1);}
{string}			{show("String",yytext(),yyline,yycolumn); return new Yytoken("String",yytext(),yyline+1,yycolumn+1);}
{operator}			{show("Operator",yytext(),yyline,yycolumn); return new Yytoken("Operator",yytext(),yyline+1,yycolumn+1);}
{int}				{show("Integer",yytext(),yyline,yycolumn); return new Yytoken("Integer",yytext(),yyline+1,yycolumn+1);}
.					{show("Error",yytext(),yyline,yycolumn); return new Yytoken("Unknown",yytext(),yyline+1,yycolumn+1);}

 